<?php

/**
 * This is the model class for table "{{user_profile}}".
 *
 * The followings are the available columns in table '{{user_profile}}':
 * @property string $user_id
 * @property string $user_identity
 * @property string $address
 * @property string $birthday
 * @property string $cell_phone
 */
class UserProfile extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return UserProfile the static model class
	 */
	public static function model($className=__CLASS__) {return parent::model($className);}

	/**
	 * @return string the associated database table name
	 */
	public function tableName() {return '{{user_profile}}';}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// Define only rules for those attributes that will receive user inputs.
		return array(
			array('user_id', 'required'),
			array('user_id, cell_phone', 'length', 'max'=>20),
			array('user_identity, birthday', 'length', 'max'=>10),
			array('address', 'length', 'max'=>500),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, user_identity, address, birthday, cell_phone', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
		);
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' 	=> Yii::t('userprofile', 'User'),
			'user_identity' 	=> Yii::t('userprofile', 'User Identity'),
			'address' 	=> Yii::t('userprofile', 'Address'),
			'birthday' 	=> Yii::t('userprofile', 'Birthday'),
			'cell_phone' 	=> Yii::t('userprofile', 'Cell Phone'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id,false);
		$criteria->compare('user_identity',$this->user_identity,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('cell_phone',$this->cell_phone,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
			'sort'=>array('defaultOrder'=>'sort ASC, id DESC'),
			'pagination'=>array('pageSize'=>Yii::app()->session->get('adminPageSize',25)),
		));
	}
}